import axios from '@/utils/request'
export default {
  StoreProduct: {
    form: {
      fields: [
        'store',
        {
          property: 'product',
          relation_filter: {
            '@filter': 'entity.getIsOnSale() == true',
            limit: 1000,
            '@order': 'entity.id|DESC'
          }
        },
        {
          property: 'listOrder',
          default_value: 255
        },
        {
          property: 'isOnSale',
          default_value: true
        }
      ]
    },
    list: {
      query: {
        '@filter': `entity.getProduct().getIsOnSale() == true`,
        '@expands': "['entity.product']",
        '@order': 'entity.listOrder|ASC,entity.id|ASC'
      },
      list_filter: {
        'store.id': () => {
          return axios
            .get('/manage/stores', { params: { limit: 1000 }})
            .then(res =>
              Object.assign(
                { __label: '门店' },
                ...res.data.map(v => {
                  return { [v.id]: v.name }
                })
              )
            )
        },
        'product.name': '产品'
      },
      list_display: [
        'id',
        'store',
        'product',
        { property: 'listOrder', editable: true },
        {
          property: 'isOnSale',
          editable: true
        }
      ]
    }
  }

}
